package com.a008cjx.myrecyclerview508cjx.model;

import com.a008cjx.myrecyclerview508cjx.activity.LoginActivity;
import com.a008cjx.myrecyclerview508cjx.bean.UserBean;
import com.a008cjx.myrecyclerview508cjx.iface.LoginListener;
import com.a008cjx.myrecyclerview508cjx.service.LoginService;
import com.squareup.picasso.Picasso;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Administrator on 2017/5/28.
 */

public class LoginModel {
    Retrofit retrofit;
    private static String BASEURL="http://amicool.neusoft.edu.cn/";


    //final static String PREFNAME="Pref_login";
    public LoginModel() {
        retrofit =new Retrofit.Builder()
                .baseUrl(BASEURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    public void login(String userName, String passWord, final LoginListener listener){
        LoginService service=retrofit.create(LoginService.class);
        Call<UserBean> call=service.getlogin(userName,passWord);
        call.enqueue(new Callback<UserBean>() {
            @Override
            public void onResponse(Call<UserBean> call, Response<UserBean> response) {
                if (response.body()!=null&&response.isSuccessful())
                    listener.onResponse(response.body());
                else{
                    listener.onFail("onResponse fail");
                }
            }

            @Override
            public void onFailure(Call<UserBean> call, Throwable t) {
                    listener.onFail(t.toString());
            }
        });
    }
}
